package me.timlong.alibaba;

import java.util.Scanner;

public class Main {

    // 如果chars中有char c，则将chars中的c换到最后一个位置
    public static boolean swapChars(char[] chars, char c, int index){
        int i = index;
        while(i >= 0 && chars[i] != c)
            i--;

        int equalIndex = i;
        if(equalIndex >= 0){
            for (int j = equalIndex + 1; j <= index ; j++) {
                chars[j-1] = chars[j];
            }
            chars[index] = c;
            return true;
        } else{
            return false;
        }
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String str1 = sc.nextLine();
        String str2 = sc.nextLine();

        int len1 = str1.length();
        int len2 = str1.length();

        if(len1 != len2) {
            System.out.println("-1");
            return;
        }

        char[] chars1 = str1.toCharArray();
        char[] chars2 = str2.toCharArray();
        int times = 0;

        // 从后向前遍历chars2
        for (int i = len2 - 1; i >=0; i--) {
            if(chars2[i] != chars1[i]) {
                if(Main.swapChars(chars1, chars2[i], i))
                    times++;
                else{
                    System.out.println("-1");
                    return;
                }
            }
            else{
                continue;
            }
        }
        System.out.println(times);

    }
}
